/**
 *  Copyright Matt Silbernagel 2010
 *  
 *	This file is part of MobilePrinting.
 *
 *	MobilePrinting is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  MobilePrinting is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with MobilePrinting.  If not, see <http://www.gnu.org/licenses/>.
 */

package edu.uc.labs.MobilePrinting.Prefs;

import java.io.File;
import java.io.IOException;

import javax.xml.parsers.ParserConfigurationException;
import javax.xml.xpath.XPathExpressionException;

import org.w3c.dom.Document;
import org.xml.sax.SAXException;

import edu.uc.labs.MobilePrinting.OSUtils.Parser;

/**
 * Parses the given preferences xml file
 * @author Matt Silbernagel
 *
 */
public class PreferencesParser extends Parser{
	
	public PreferencesParser() throws ParserConfigurationException {
		super();		
	}

	public Preferences parse(File f) throws SAXException,IOException, XPathExpressionException {
		
		logger.debug("now Parsing " + f.getAbsolutePath());
		Document doc = builder.parse(f);
		
		// Create a new empty Preference object
		Preferences pref = new Preferences();
		pref.setAutoUpdate(path.evaluate("/Configuration/General/autoupdate", doc));
		pref.setDeleteOnExit(path.evaluate("/Configuration/General/deleteprinteronexit", doc));
		pref.setStartAtLogin(path.evaluate("/Configuration/General/startatlogin", doc));
		pref.setConfigServer(path.evaluate("/Configuration/Advanced/configserver", doc));
		pref.setPrinterName(path.evaluate("/Configuration/Advanced/printername", doc));
		pref.setLogLevel(path.evaluate("/Configuration/Advanced/loglevel", doc));
		
		return pref;
		
	}
	
	
	
	
}
